﻿using Leeder.Util.Excel;
using Leeder.Util.Excel.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TestExcel
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public class TestModel
        {
            public string value1 { get; set; }
            public string value2 { get; set; }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog myDialog = new FolderBrowserDialog();
            myDialog.ShowNewFolderButton = false;
            myDialog.Description = "选择你要设置的文件夹或目录 ";
            string path = string.Empty;
            if (myDialog.ShowDialog() == DialogResult.OK)
                path = myDialog.SelectedPath;
            else
            {
                myDialog.Dispose();
                return;
            }
            ExcelConfig excelConfig = new ExcelConfig();
            List<ColumnEntity> columnEntities = new List<ColumnEntity>();
            //columnEntities.Add(new ColumnEntity { Column = "Value", ExcelColumn = "检测OK值" });
            //columnEntities.Add(new ColumnEntity { Column = "CheckResult", ExcelColumn = "检测结果" });
            //columnEntities.Add(new ColumnEntity { Column = "CheckValue", ExcelColumn = "检测温度值" });
            //columnEntities.Add(new ColumnEntity { Column = "CheckTime", ExcelColumn = "检测时间" });
            excelConfig.ColumnEntity = columnEntities;
            //string path = ".\\Excel\\";
            excelConfig.FileName = path + "\\除雾检测记录表.xlsx";
            List<TestModel> list = new List<TestModel>();
            for (int i = 0; i < 5; i++)
            {
                list.Add(new TestModel
                {
                    value1 = "值" + i,
                    value2 = "值" + i,
                });
            }
            try
            {
                ExcelHelper<TestModel>.ExcelImport(list, excelConfig);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
